import os

import requests

from 接口自动化.interface_auto.apis.base_api import BaseApi
from 接口自动化.interface_auto.utils.utils import Utils


class WeWork(BaseApi):
    def __init__(self):
        self.data = self.read_conf()
        self.base_url = self.data["base_url"]
        self.corpid = self.data["corpid"]

    def get_token(self, secret):
        url = f'{self.base_url}/cgi-bin/gettoken'
        params = {
            "corpid": self.corpid,
            "corpsecret": secret
        }
        r = self.send("POST", url, params=params)
        token = r.json()["access_token"]
        return token

    def read_conf(self):
        file_path = Utils.root_path() + "/conf/test_wework.yaml"
        data = Utils.read_yaml(file_path)
        return data

    def get_conf_env(self):
        """
        多环境切换
        :return:
        """
        env = os.getenv("env", default="test")
        return env
